package com.forevershine.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.cohesion.bootstrap.common.PublicConstants;
import com.forevershine.business.context.ContextBuilder;
import com.forevershine.business.model.StyleDetail;
import com.forevershine.business.model.Task;
import com.forevershine.business.service.impl.TaskServiceImpl;
import com.forevershine.common.OrderStage;
import com.opensymphony.xwork2.ActionContext;

public class PendingListAction extends BaseAction {

private static Log log = LogFactory.getLog(TopMenuAction.class);
	
	private StyleDetail briefVo  = new StyleDetail();
	private List<Task> pendingList = new ArrayList<Task>();
	
	
	


	public List<Task> getPendingList() {
		return pendingList;
	}


	public void setPendingList(List<Task> pendingList) {
		this.pendingList = pendingList;
	}


	private static final long serialVersionUID = 1L;
	


	public StyleDetail getBriefVoModel() {
		return briefVo;
	}


	public void setBriefVoModel(StyleDetail model) {
		this.briefVo = model;
	}


	
	
	


	private List<Task> loadDefaultPendingList() {
		 
		 Object  userId = ActionContext.getContext().get(PublicConstants.USER_ID);
		 String stageName = (String)ActionContext.getContext().getParameters().get(OrderStage.class.getName());
		 
		 if (userId == null || userId.toString().equals(""))
		 {
			userId=1;
//			throw new IllegalStateException("User are not logined in."); 
		 }
		 OrderStage orderStage = null;
		 if (stageName!= null)
		 {
		 orderStage = OrderStage.valueOf(stageName);
		 }
		 else
		{
//			throw new IllegalStateException("Stage name is not determined."); 
			
		}
		return loadPendingList(Integer.valueOf(userId.toString()), orderStage);
		
		
	}


	private List<Task> loadPendingList(Integer userId, OrderStage orderStage2) {
		TaskServiceImpl loadPendingService = (TaskServiceImpl) ContextBuilder.getContext().getInstance(TaskServiceImpl.class);
		List<Task> list = new ArrayList<Task>();
		loadPendingService.loadTasksByUserId(userId, list);
		return list;
	}


	@Override
	protected String service() {
		this.pendingList = loadDefaultPendingList();
		return SUCCESS;
	}
	
	
}
